
// pages/test/test.js 
var app = getApp();
var hostUrl = require("../../host.js");

Page({
  /** 
   * 统一满分为5星 
   */
  data: {

    total_flag: true, //控制描述显示
    total: '',         //控制显示描述标题
    text: '',          //控制描述文字
    avatarUrl: '',
    nickName: '',
    have_calculation: 0,
    icon_text: "",
    
    arr: [2, 4, 6, 8, 10],

    //权重
    areaIndex1: 0,
    areaIndex1_: 0,
    area1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],

    //权重
    areaIndex2: 0,
    areaIndex2_: 0,
    area2: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],


    //权重
    areaIndex3: 0,
    areaIndex3_: 0,
    area3: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],


    //权重
    areaIndex4: 0,
    areaIndex4_: 0,
    area4: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],

    areaIndex5: 0,
    areaIndex5_: 0,
    area5: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  },
  onLoad: function (options) {

    // console.log(url);
    if (wx.getStorageSync('userInfo')) {
      this.setData({
        avatarUrl: JSON.parse(wx.getStorageSync('userInfo')).avatarUrl,
        nickName: JSON.parse(wx.getStorageSync('userInfo')).nickName,
      });
    }

    this.setData({
      have_calculation: app.globalData.have_calculation
    })
    if (app.globalData.have_calculation == 1) {
      this.setData({
        icon_text: "报告记录"
      })
    } else {
      this.setData({
        icon_text: "返回首页"
      })
    }
    //请求文字描述接口并缓存数据
    var url = hostUrl.score_weight_msg;

    var paramsMd5 = app.paramsMd5({ utoken: wx.getStorageSync("utoken") });
    var that = this;
    wx.request({
      url: url,
      data: paramsMd5,
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      dataType: 'json',
      success: function (response) {
        if (response.data.status) {
          that.setData({
            startup_ideas: response.data.msg.startup_ideas,
            business_plan: response.data.msg.business_plan,
            field_specialization: response.data.msg.field_specialization,
            responsibility_risk: response.data.msg.responsibility_risk,
            founder_responsibility: response.data.msg.founder_responsibility,
          })
        }
      }
    });


    this.$wuxToptips = app.Wux().$wuxToptips;
  },

  bindPickerChange: function (e) {
    var area = Number(e.detail.value) + 1;
    switch (e.currentTarget.id) {
      case "1":
        this.setData({
          areaIndex1: e.detail.value,
          areaIndex1_: area,
          // viewList1: new Array(this.data.area1[e.detail.value])
        });
        return;
      case "2":
        this.setData({
          areaIndex2: e.detail.value,
          areaIndex2_: area,
          // viewList2: new Array(this.data.area2[e.detail.value])
        });
        return;
      case "3":
        this.setData({
          areaIndex3: e.detail.value,
          areaIndex3_: area,
          // viewList3: new Array(this.data.area3[e.detail.value])
        });
        return;
      case "4":
        this.setData({
          areaIndex4: e.detail.value,
          areaIndex4_: area,
        });
        return;
      case "5":
        this.setData({
          areaIndex5: e.detail.value,
          areaIndex5_: area,
        });
        return;
      default:
        break;
    }
    // console.log(e)
    // console.log(e.currentTarget.id)
  },

  //页面跳转
  navigateTo: function (e) {
    var that = this;
    var num = 0;
    var value = e.detail.value;
    for (var key in value) {
      num += Number(value[key]);
    }

    if (num == 0) {


      var hideToptips = that.$wuxToptips.show({
        timer: 3000,
        text:  '权重总数不得为0',
        success: () => console.log("")
      });
      return;
    }

    app.globalData.contribution_score_weight_list = e.detail.value;
    app.globalData.entity.contribution_score_weight_list = JSON.stringify(e.detail.value);

    app.globalData.currentBoss = 0;
    app.globalData.shareDistribution = 0;

    wx.navigateTo({
      url: '/pages/gongxianpingfen/index',
    });
  },

  navigateBack: function () {
    wx.navigateBack({

    });
  },

  show: function (e) {
    var that = this;
    
    switch (e.currentTarget.id) {
      case "1":
        that.setData({
          total: '创业点子',
          text: that.data.startup_ideas,
        });
        break;
      case "2":
        that.setData({
          total: '商业计划书',
          text: that.data.business_plan,
        });
        break;
      case "3":
        that.setData({
          total: '领域专业性',
          text: that.data.field_specialization,
        });
        break;
      case "4":
        that.setData({
          total: '担当及风险',
          text: that.data.responsibility_risk,
        });
        break;
      case "5":
        that.setData({
          total: '创始人责任',
          text: that.data.founder_responsibility,
        });
        break;
      default:
        break;
    }
    that.setData({ total_flag: false })
  },
  //消失

  hide: function () {

    this.setData({ total_flag: true })
  },

  icon_redirectTo: function () {
    var that = this;
    if (that.data.have_calculation == 1) {
      wx.redirectTo({
        url: '/pages/history/index',
      })
    } else {
      wx.redirectTo({
        url: '/pages/index/index',
      })
    }
  },
})  
